import { createStore } from "vuex";
import persistedState from "vuex-persistedstate";

const store = createStore({
  plugins: [persistedState()],

  state: {
    userInfo: {},
    isCollapse: false,
  },
  mutations: {
    setUserInfo(state, payload) {
      //   localStorage.setItem("userInfo", JSON.stringify(payload));
      state.userInfo = payload; //存储用户信息
    },
    changeTrue(state) {
      state.isCollapse = true;
    },
    changeFalse(state) {
      state.isCollapse = false;
    },
  },
  getters: {
    userInfos(state) {
      return localStorage.getItem("userInfo")
        ? localStorage.getItem("userInfo")
        : state.userInfo;
    },
  },
});
export default store;
